#include<stdio.h>
int test(int day, int* str, int size)
{
    int sum = 0;
    int* copystr = str;
    while (day--)
    {
        for (int i = 0; i < size; i++)
        {
            if (copystr[i] != 0)
            {
                sum += copystr[i];
                copystr[i]--;
            }
        }
    }
    return sum;
}
int main()
{
    int size = 0;
    scanf("%d", &size);
    int arr[size];
    int str[size];
    for (int i = 0; i < size; i++)
    {
        scanf("%d", &arr[i]);
        getchar();
    }

    for (int i = 0; i < size; i++)
    {
        scanf("%d", &str[i]);
        getchar();
    }
    int k = 0;
    scanf("%d", &k);
    while (k--)
    {
        int day = 0;
        scanf("%d", &day);
        int sum = test(day, str, size);
        printf("%d\n", sum);
    }
    return 0;
}